<?php

namespace App\Providers;

use App\Models\Category;
use Illuminate\Support\ServiceProvider;
use DB;
use Log;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        DB::listen(function ($query) {
//            Log::debug($query->sql, $query->bindings);
            Log::debug(vsprintf(str_replace("?", "'%s'", $query->sql), $query->bindings));//替换sql中的变量
        });


    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        view()->composer('layouts.main', function ($view) {
            $categoties = Category::query()->get();
            $view->with('categories', $categoties);
        });

    }
}
